package com.gzhryc.socket;

public class SocketEvent {

	protected SocketNode node;
	protected SocketMessage message;
	protected Throwable cause;
	
	public SocketEvent(SocketNode socketNode) {
		this.node = socketNode;
	}
	
	public SocketEvent(SocketNode socketNode,SocketMessage message) {
		this.node = socketNode;
		this.message = message;
	}
	
	public SocketEvent(SocketNode socketNode,Throwable cause) {
		this.node = socketNode;
		this.cause = cause;
	}
    
	public Throwable getCause() {
		return cause;
	}

	public SocketMessage getMessage() {
		return message;
	}
	
	public <T extends SocketMessage> T getMessage(Class<T> pClass) {
		if(message != null) {
			return pClass.cast(message);
		}
		return null;
	}
	
	public SocketNode getSocketNode() {
		return this.node;
	}
	
	public <T extends SocketNode> T getSocketNode(Class<T> pClass) {
		return this.node.changeTo(pClass);
	}
}